import { Behaviour } from "./Behaviour";
import { GameObject } from "./GameObject";
import { System } from "./System";


export class LifeCycleSystem extends System {

    onAddBehaviour(gameObject: GameObject, behaviour: Behaviour) {
        behaviour.onStart();
        if (this.engine.runMode == "running") {

            const add1 = document.getElementById("addSplinter")
            add1.hidden = true;
            const add2 = document.getElementById("addDiamond")
            add2.hidden = true;
            const add3 = document.getElementById("addGold")
            add3.hidden = true;
            const add4 = document.getElementById("addStone")
            add4.hidden = true;
            const add5 = document.getElementById("addBrick1")
            add5.hidden = true;
            const add6 = document.getElementById("addBrick2")
            add6.hidden = true;
            const add7 = document.getElementById("addFloor")
            add7.hidden = true;
            const add8 = document.getElementById("addIce")
            add8.hidden = true;
            const add9 = document.getElementById("addGoldshell")
            add9.hidden = true;
            const add10 = document.getElementById("addPurpleshell")
            add10.hidden = true;
            const add11 = document.getElementById("addRock")
            add11.hidden = true;
            const add12 = document.getElementById("addWater")
            add12.hidden = true;
            const add13 = document.getElementById("addMouster")
            add13.hidden = true;

        }
    }


    // onRemoveBehaviour(gameObject: GameObject, behaviour: Behaviour) {
    //     behaviour.onEnd();
    // }



    onTick(duringTime: number) {
        this.gameObjectOnFixUpdate(this.rootGameObject, duringTime);
    }

    onFrame(duringTime: number) {

        this.gameObjectOnUpdate(this.rootGameObject, duringTime);
    }

    gameObjectOnUpdate(gameObject: GameObject, duringTime: number) {
        for (const behaviour of gameObject.behaviours) {
            behaviour.onUpdate(duringTime);
        }
        for (const child of gameObject.children) {
            this.gameObjectOnUpdate(child, duringTime);
        }
    }

    gameObjectOnFixUpdate(gameObject: GameObject, duringTime: number) {
        for (const behaviour of gameObject.behaviours) {
            behaviour.onFixUpdate(duringTime);
        }
        for (const child of gameObject.children) {
            this.gameObjectOnFixUpdate(child, duringTime);
        }
    }
}
